package com.handwriting.backend.message;

import com.handwriting.backend.utils.JsonUtils;
import lombok.Data;

@Data
public class Response<T> {
    public static final int OK = 20000;
    public static final int Error = 40000;
    public static final int UserNotFoundError = 40001;
    public static final int PasswordError = 40002;
    public static final int AlreadyExistError = 40003;

    private static final JsonUtils encoder = new JsonUtils();

    private int status;
    private String msg;
    private T data;

    private Response(int status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Response<T> ok(T data) {
        return get(OK, "OK", data);
    }

    public static <T> Response<T> error(String msg) {
        return get(Error, msg, null);
    }

    public static <T> Response<T> error(String msg, int code) {
        return get(code, msg, null);
    }

    public static <T> Response<T> get(int status, String msg, T data) {
        return new Response<T>(status, msg, data);
    }
}
